import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import Home from "../views/Home.vue";
const menu = [
  {
    path: "/profile",
    name: "Profile",
    component: () => import(/* webpackChunkName: "profile" */ "../views/Profile.vue"),
    // redirect?
    // children?
    // meta?
    // props?
    // alias?
    // beforeEnter?
  },
  {
    path: "/c-api",
    name: "CApi",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "c-api" */ "../views/CApi.vue"),
    children: [
      {
        // NOTICE: 子的path前不加斜杠`/`
        path: '',// 提供一个`空的`子路由,供父级默认匹配
        alias: 'responsive',// fullPath: '/c-api/responsive',
        name: 'Responsive',// `/a` 的别名是 /b，意味着，当用户访问 /b 时，URL 会保持为 /b，但是路由匹配则为 /a，就像用户访问 /a 一样。
        component: () => import(/* webpackChunkName: "c-api-responsive" */ "@/components/CApi/Responsive.vue"),
        props: {
          // 不仅需要在route传递,还要在组件内部接收
          point: "Responsive"
        }
      },
      {
        path: 'watch',
        name: 'Watch',
        component: () => import(/* webpackChunkName: "c-api-watch" */ "@/components/CApi/Watch.vue"),
        props: {
          point: "Watch & template refs"
        }
      },
      {
        path: 'life-cycle',
        name: 'LifeCycle',
        component: () => import(/* webpackChunkName: "c-api-life-cycle" */ "@/components/CApi/LifeCycle.vue"),
        props: {
          point: "life-cycle"
        }
      },
      {
        path: 'provide-inject',
        name: 'ProvideInject',
        component: () => import(/* webpackChunkName: "c-api-provide-inject" */ "@/components/CApi/ProvideInject.vue"),
        props: {
          point: "provide-inject"
        }
      },
    ]
  },
];
const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "Home",
    component: Home
  },
  {
    path: "/login",
    name: "Login",
    component: () => import(/* webpackChunkName: "login" */ "@/components/common/Login.vue"),
  },
  ...menu
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
});

export default router;
